// pages/query/query.js
import { $wuxCalendar, $wuxSelect } from "../../components/wux/index";
const api = require('../../utils/request.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    invoiceNo:"",
    startValue: [],
    endValue: [],
    options: [
      {
        text: '全部',
        type: 'radio',
        options: [{
          id:0,
          text: '全部',
        },
          {
            id: "WC",
            text: '未确认',
          },
          {
            id: "CO",
            text: '医院已确认',
          }
        ]
      }
      ],
    stateId: 0,
    stateValue: "",
    currentDate: new Date().getTime(),
    maxDate: new Date().getTime(),
    list: [
      {
        title: "已确认张数 ",
        desc: "23",
        slot: true
      },
      {
        title: "已确认金额 ",
        desc: "满100减20",
        slot: true
      },
      {
        title: "未确认张数 ",
        desc: "21323213",
        slot: true
      },
      {
        title: "未确认金额 ",
        desc: "21321321321312",
        slot: true
      }
    ],
    title: {
      noName: "发票号码:\xa0\xa0",
      codeName: "发票代码:\xa0\xa0",
      dateName: "发票日期:\xa0\xa0",
      moneyName: "不含税金额:\xa0\xa0",
      stateName: "状态:\xa0\xa0",
    },
    table: [
      {
        no: "321312",
        code: "23",
        stateName: "状态 ",
        state: "未确认",
        date: "20180806",
        money: "12321.4545"
      },
      {
        noName: "发票号码",
        no: "222222222",
        codeName: "发票代码",
        code: "23",
        stateName: "状态",
        state: "未确认",
        dateName: "发票日期",
        date: "20180806",
        moneyName: "不含税金额",
        money: "12321.4545"
      },
      {
        noName: "发票号码",
        no: "4444444444",
        codeName: "发票代码",
        code: "23",
        stateName: "状态",
        state: "已确认",
        dateName: "发票日期",
        date: "20180806",
        moneyName: "不含税金额",
        money: "12321.4545"
      },
      {
        noName: "发票号码",
        no: "213213123213",
        codeName: "发票代码",
        code: "23",
        stateName: "状态",
        state: "未确认",
        dateName: "发票日期",
        date: "20180806",
        moneyName: "不含税金额",
        money: "1231.4545"
      }
    ]
  },
  onInputInvocieNo(e){

  },
  openStartCalendar() {
    $wuxCalendar().open({
      value: this.data.startValue,
      onChange: (startValue, displayValues) => {
        console.log("onChange", startValue, displayValues);
        this.setData({
          startValue :displayValues
        })
      }
    });
  },
  openEndCalendar() {
    $wuxCalendar().open({
      value: this.data.endValue,
      onChange: (endValue, displayValues) => {
        console.log("onChange", endValue, displayValues);
        this.setData({
          endValue: displayValues
        })
      }
    });
  },
  //点击状态栏事件
  handleChange(e) {
    console.log(JSON.stringify(this.data.options))
    console.log("state---" + JSON.stringify(e.detail));
    this.setData({
      stateId: e.detail.optkey
    })
    console.log("select ---" + this.data.stateId)
  },
  onClickState() {
    console.log("点击了状态");
    $wuxSelect("#wux-select").open({
      value: this.data.stateId,
      options: ["已确认", "未确认"],
      onConfirm: (value, index, options) => {
        console.log("onConfirm", value, index, options);
        if (index !== -1) {
          this.setData({
            stateId:value,
            stateValue: options[index]
          })
        }
      }
    });
  },
  onSearch(e){
    let data ;
    if (this.data.startValue != null && this.data.startValue.length>0){
      data.DateInvoicedFrom = this.data.startValue
    }
    if (this.data.endValue != null && this.data.endValue.length > 0) {
      data.DateInvoicedTo = this.data.endValue
    }
    if (this.data.stateId != null && this.data.stateId.length > 0) {
      data.InvoiceCheckStatus = this.data.stateId
    }
    api.fetchRequest('invoiceCheckAction/queryInvoiceSummary.do', data)
    .then(function (res) {
     
     
    }).catch(function (res) {
      console.log("发生异常：" + res)
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
    })
  },
  onScan(e){
    //invoiceCheckAction / queryInvoiceSummary.do
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})